package com.example.work3.controller;
import com.example.work3.entity.Major;
import com.example.work3.entity.Student;
import com.example.work3.entity.User;
import com.example.work3.pojo.ChangPassword;
import com.example.work3.pojo.Result;
import com.example.work3.service.MajorService;
import com.example.work3.service.StudentService;
import com.example.work3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin("http://localhost:8080")
@RequestMapping("/user")
public class UserController {
    @Autowired
    private MajorService majorService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private UserService userService;
    //专业选择(w)
    @RequestMapping("/major")
    public List<Major> getMajor(){
     return majorService.getALl();
    }
    //电话检验(w)
    @RequestMapping("/phoneExist")
    public boolean getPhone(@RequestParam("phone") String phone){
      return studentService.isExistPhone(phone);
    }
    //注册(w)
    @RequestMapping("/register")
    public User regist(@RequestBody Student student){
        System.out.println(student);
        return studentService.addStudent(student);
    }
    //登录(w)
    @RequestMapping("/login")
    public Result login(@RequestParam("account") String account, @RequestParam("password") String password){
        System.out.println(account+"  "+password);
        return userService.login(account,password);
    }
    //修改密码
    @RequestMapping("/updatePassword")
    public boolean updatePassword(@RequestBody ChangPassword changPassword){
        System.out.println(changPassword);
        return userService.updatePassword(changPassword.getAccount(),changPassword.getNewWord());
    }

}
